package cn.com.jsepc.rep.reffact;

import java.util.ArrayList;
import java.util.List;
import java.util.Vector;
import java.util.Hashtable;
import net.sf.json.JSONArray;
import cn.com.jsepc.rep.comm.ConstUtil;
import cn.com.jsepc.rep.vo.ReportVO;
import com.jarp.db.DAO;

public class reffact_table {
	// 加载数据
	public String getGrid(String start, String limit, String KeyWord_0) {
		String res = "";
		DAO dao = new DAO();
		try {
			List<ReportVO> lstResults = new ArrayList<ReportVO>();
			int iStart = Integer.parseInt(start);
			int iPageSize = Integer.parseInt(limit);
			int iPage =  iStart/iPageSize + 1;
			StringBuffer str = new StringBuffer();
			//通过限定条件，获取用户所需数据
			str.append("select a.*,b.CATANAME,c.NAME DEPTNAME from TB_REPORT a ");
			str.append(" left join tb_catalog b on b.CATAID=a.CATAID ");
			str.append(" left join TB_CORP_DEPT c on c.ID=a.DEPARTMENT ");
			str.append(" where 1 = 1 ");
			str.append(" and REFFACT is not null");
			str.append(" and SOURCETYPE = 2");
			str.append(" order by a.cataid");
			Vector v = dao.getDataSet(ConstUtil.DBNAME, str.toString(),iPage,iPageSize);
			if (v != null) {
				for (int i = 0; i < v.size(); i++) {
					Hashtable hashRows = (Hashtable) v.get(i);
					ReportVO repVO = new ReportVO();
					repVO.setRepid((String) hashRows.get("REPID"));
					repVO.setRepcode((String) hashRows.get("REPCODE"));
					repVO.setRepname((String) hashRows.get("REPNAME"));
					repVO.setCataid((String) hashRows.get("CATAID"));
					repVO.setCataname((String) hashRows.get("CATANAME"));
					repVO.setRepdesc((String) hashRows.get("REPDESC"));
					repVO.setDesc((String) hashRows.get("CALDESC"));
					repVO.setDataprec((String) hashRows.get("DATAPREC"));
					repVO.setDataunit((String) hashRows.get("DATAUNIT"));
					repVO.setDepartment((String) hashRows.get("DEPTNAME"));
					repVO.setDepartmentid((String) hashRows.get("DEPARTMENT"));
					repVO.setSourcetype((String) hashRows.get("SOURCETYPE"));
					repVO.setDatatype((String) hashRows.get("DATATYPE"));
					repVO.setUpdatetime((String) hashRows.get("UPDATETIME"));
					repVO.setReffact((String) hashRows.get("REFFACT"));
					repVO.setRepvaluecol((String) hashRows.get("REPVALUECOL"));
					repVO.setIssum((String) hashRows.get("ISSUM"));
					repVO.setIsvalid((String) hashRows.get("ISVALID"));
					lstResults.add(repVO);//将数据放置结果集中
				}
			}
			
			JSONArray json = new JSONArray();
			StringBuffer str1 = new StringBuffer();
			str1.append("select count(1) CNT from (");
			str1.append(str);
			str1.append(" ) z ");
			String totalCount = dao.getDataValue(ConstUtil.DBNAME, str1.toString());
			json = JSONArray.fromObject(lstResults);
			res = "{totalCount:" + totalCount + ",data:" + json.toString()
					+ "}";
		} catch (Exception ex) {
			ex.printStackTrace();
		}
		return res;
	}
}
